//
//  JTCommentTableViewCell.m
//  百思不得姐
//
//  Created by Robin Zhang on 2017/1/18.
//  Copyright © 2017年 BeiJingWangDianJieTong. All rights reserved.
//

#import "JTCommentTableViewCell.h"
#import "JTComment.h"
#import "JTUser.h"

@interface JTCommentTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *profileImageView;
@property (weak, nonatomic) IBOutlet UIImageView *sexImageView;
@property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
@property (weak, nonatomic) IBOutlet UILabel *likeCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIButton *voiceButton;

@end

@implementation JTCommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mainCellBackground"]]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setComment:(JTComment *)comment {
    
    _comment = comment;
    
    [self.usernameLabel setText:comment.user.username];
    [self.contentLabel setText:comment.content];
    
    [self.likeCountLabel setText:[NSString stringWithFormat:@"%zd", comment.like_count]];
    [self.profileImageView setHeader:comment.user.profile_image];
    
    NSString *sexImageName = [comment.user.sex isEqualToString:JTUserSexMale]?@"Profile_manIcon":@"Profile_womanIcon";
    [self.sexImageView setImage:[UIImage imageNamed:sexImageName]];
    
    /** 显示文字内容或音频评论 */
    if (comment.voiceuri.length) {
        
        [self.voiceButton setHidden:NO];
        [self.voiceButton setTitle:[NSString stringWithFormat:@"%zd''", comment.voicetime] forState:UIControlStateNormal];
    } else {
        
        [self.voiceButton setHidden:YES];
    }
}

@end
